package com.demo.menu;

import com.jfinal.kit.StringKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;
import java.sql.Date;
@SuppressWarnings("serial")
public class WxMenu extends Model<WxMenu>{
    public static final WxMenu dao = new WxMenu();


    public List<WxMenu> findAll() {
        return find("select * from wx_menu");
    }
    /**
     * @param   where
     * @return  Record
     */
    public List<Record> findAlls(String where) {
        String sqlExp = " from wx_menu";
        if(StringKit.notBlank(where)){
            sqlExp += " where " + where;
        }
        String order =" order by sxh";
        return Db.find( "select * " +sqlExp +order);

    }

    public List<Record> findtree(String where) {
        String order =" order by sxh";
        return  Db.find("select *, pid as pId from wx_menu " + where+order);
    }

    public List<Record> findbymenu(String where) {
        String order =" order by sxh";
        return  Db.find("select *,(select count(*) from wx_menu b where b.pid=a.id) as num from wx_menu a" +
                "" + where+order);
    }

    public Page<WxMenu> page(int pageNumber, int pageSize, String where) {
        String sqlExp = "from wx_menu";
        if(StringKit.notBlank(where)){
            sqlExp += " where " + where;
        }
        return paginate(pageNumber, pageSize, "select *", sqlExp);
    }

  
}

